use std::error::Error;
use std::fmt::{Display, Formatter};
use std::io;

// Assuming you have already defined the ApiCallError with Thiserror crate
// If not, define it like this:
#[derive(Debug)]
pub enum ApiCallError {
    CountOutOfRange,
    UnknownMarket,
    Io(io::Error),
}

impl Error for ApiCallError {}

impl Display for ApiCallError {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        match self {
            ApiCallError::CountOutOfRange => {
                write!(f, "Count cannot be greater than or equal to 2000")
            },
            ApiCallError::UnknownMarket => {
                write!(f, "market must be MARKET_SZ = 0  # 深圳 MARKET_SH = 1  # 上海")
            }
            ApiCallError::Io(err) => err.fmt(f),
        }
    }
}

impl From<io::Error> for ApiCallError {
    fn from(err: io::Error) -> Self {
        ApiCallError::Io(err)
    }
}
